package com.bwstudio.demo.consumer.util;

import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;

import com.alibaba.cloud.sentinel.rest.SentinelClientHttpResponse;
import com.alibaba.csp.sentinel.slots.block.BlockException;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ExceptionUtil {

//	public static ClientHttpResponse handleException(HttpRequest request, byte[] body, ClientHttpRequestExecution execution, BlockException exception) {
//		log.info("");
//		return null;
//    }
	
    public static SentinelClientHttpResponse handleException(HttpRequest request,
            byte[] body, ClientHttpRequestExecution execution, BlockException ex) {
        log.error("Oops: " + ex.getClass().getCanonicalName());
        return new SentinelClientHttpResponse("custom block info");
    }
    
    public static SentinelClientHttpResponse fallback(HttpRequest request,
            byte[] body, ClientHttpRequestExecution execution, BlockException ex) {
    	log.error("fallback: " + ex.getClass().getCanonicalName());
        return new SentinelClientHttpResponse("custom fallback info");
    }
}
